package com.lagou.assignment;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class DataReducer extends Reducer<DataBean, NullWritable, DataBean, NullWritable> {

    /**
     * 因为在进入reducer时，已经是排序好的数据了
     * 只需要每个计算ranking+1，就正好是排名数据
     * 而且只跑了一个task能保证数据正确性
     */
    int ranking = 0;

    @Override
    protected void reduce(DataBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {
            ranking +=1;
            key.setRanking(ranking);
            context.write(key, value);
        }
    }
}
